package com.mini.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mini.entity.EpidemicNewsInfo;
import com.mini.entity.EpidemicNewsInfoDto;
import com.mini.entity.Result;
import com.mini.service.EpidemicNewsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hy
 * @since 2021-04-27
 */
@RestController
@RequestMapping("/info")
@CrossOrigin
@Api(description = "疫情、疫苗新闻", value = "疫情、疫苗新闻", tags = "疫情、疫苗新闻")
public class EpidemicNewsInfoController {
    @Autowired
    private EpidemicNewsInfoService epidemicNewsInfoService;

    @ApiOperation(value = "查询")
    @GetMapping("/find/{current}/{size}/{flag}")
    public Result xixi(@PathVariable(value = "current", required = true) Integer current,
                       @PathVariable(value = "size", required = true) Integer size,
                       @PathVariable(value = "flag", required = true) Integer flag) {
        QueryWrapper<EpidemicNewsInfo> wrapper = new QueryWrapper<>();
        wrapper.eq("flag",flag);
        Page<EpidemicNewsInfo> page = new Page<>(current, size);
        epidemicNewsInfoService.page(page, wrapper);
        return Result.success().data(page);
    }

    @PostMapping()
    public Result jiujiu(@RequestBody EpidemicNewsInfoDto epidemicNewsInfoDto) {
        EpidemicNewsInfo epidemicNewsInfo = new EpidemicNewsInfo();
        BeanUtils.copyProperties(epidemicNewsInfoDto,epidemicNewsInfo);
        return epidemicNewsInfoService.save(epidemicNewsInfo) ? Result.success() : Result.error();
    }

}

